package org.example.mallchat.websocket.adapter;

import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket;
import org.example.mallchat.domain.entity.User;
import org.example.mallchat.websocket.domain.enums.WSRespTypeEnum;
import org.example.mallchat.websocket.domain.vo.response.WSBaseResp;
import org.example.mallchat.websocket.domain.vo.response.WSLoginSuccess;
import org.example.mallchat.websocket.domain.vo.response.WSLoginUrl;

import static org.example.mallchat.websocket.domain.enums.WSRespTypeEnum.LOGIN_SUCCESS;

/**
 * @author: zzh
 * @date: 2024/12/18 15:37:36
 * @version: 1.0
 * 适配器模式！ 固定入参返回特定出参
 */
public class WebSocketAdapter {
    public static WSBaseResp<WSLoginUrl> buildLoginUrlResp(WxMpQrCodeTicket wxMpQrCodeTicket){
        WSBaseResp<WSLoginUrl> resp = new WSBaseResp<>();
        resp.setType(WSRespTypeEnum.LOGIN_URL.getType());
        resp.setData(new WSLoginUrl(wxMpQrCodeTicket.getUrl()));
        return resp;
    }

    /**
     * 构建登录成功响应对象
     * @return
     */
    public static WSBaseResp<WSLoginSuccess> buildLoginSuccessResp(User user, String token,Long power) {
        WSBaseResp<WSLoginSuccess> wsLoginSuccessWSBaseResp = new WSBaseResp<>();
        WSLoginSuccess wsLoginSuccess = new WSLoginSuccess();
        wsLoginSuccess.setToken(token);
        wsLoginSuccess.setUid(user.getId());
        wsLoginSuccess.setName(user.getName());
        wsLoginSuccess.setAvatar(user.getAvatar());
        wsLoginSuccess.setPower(Integer.parseInt(power.toString()));
        wsLoginSuccessWSBaseResp.setType(LOGIN_SUCCESS.getType());
        wsLoginSuccessWSBaseResp.setData(wsLoginSuccess);
        return wsLoginSuccessWSBaseResp;
    }

    public static WSBaseResp<WSLoginUrl> buildScanSuccessWait() {
        WSBaseResp<WSLoginUrl> resp = new WSBaseResp<>();
        resp.setType(WSRespTypeEnum.LOGIN_SCAN_SUCCESS.getType());
        resp.setData(null);
        return resp;
    }

    public static WSBaseResp<?> buildInvalidTokenResp() {
        WSBaseResp<?> resp = new WSBaseResp<>();
        resp.setType(WSRespTypeEnum.INVALIDATE_TOKEN.getType());
        resp.setData(null);
        return resp;
    }

    public static WSBaseResp<?> buildBlackYourSelfResp() {
        WSBaseResp<?> resp = new WSBaseResp<>();
        resp.setType(WSRespTypeEnum.BLACK_YOURSELF.getType());
        resp.setData(null);
        return resp;
    }

    public static WSBaseResp<?> buildBlackOtherResp() {
        WSBaseResp<?> resp = new WSBaseResp<>();
        resp.setType(WSRespTypeEnum.BLACK.getType());
        resp.setData(null);
        return resp;
    }
}
